<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">曲师商城</view>
			<input @input="inputChange" class="u-border-bottom" type="number" v-model="phone" placeholder="请输入手机号" />
			<!-- <view class="tips">未注册的手机号验证后自动创建账号</view> -->
			<button @click="submit" :style="{'background-color': bgcolor,'color': fontcolor,'margin-top': top}"
				class="getCaptcha">绑定手机号</button>
		</view>
	</view>
</template>

<script setup>
	import {
		ref
	} from "vue";
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		getPhoneCode
	} from "@/api/common/index.js";
	
	const nickName = ref('');
	onLoad((options) => {
		nickName.value = options.nickName;
		console.log(nickName.value);
	})

	const phone = ref('');
	//获取验证码
	const submit = () => {
		if (validatePhoneNumber(phone.value)) {
			//请求验证码发送
			getPhoneCode(phone.value).then((res) => {
				if (res.code === 200) {
					uni.showToast({
						title: "验证码发送成功！",
					})
					//符合手机号校验则跳转
					setTimeout(() => {
						uni.navigateTo({
							url: "/pages/register/bind/code/code?phone=" + phone.value + "&nickName=" + nickName.value
						})
					}, 1500)
				}
			})
		} else {
			uni.showToast({
				title: "手机号格式错误！",
				icon: "error"
			})
		}
	}

	//校验手机号的正则
	const validatePhoneNumber = (phone) => {
		var pattern = /^1[3-9]\d{9}$/;
		if (pattern.test(phone)) {
			return true;
		} else {
			return false;
		}
	}

	const bgcolor = ref('#fcbd71');
	const fontcolor = ref('#82848a');
	const top = ref("50px");
	const inputChange = () => {
		if (phone.value === '') {
			bgcolor.value = '#fcbd71';
			fontcolor.value = '#82848a';
		} else {
			bgcolor.value = '#f9ae3d';
			fontcolor.value = '#fff';
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;

			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
				font-size: 12px;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30px;
			}
		}

		.buttom {
			.loginType {
				display: flex;
				padding: 150rpx;
				justify-content: space-between;

				.item {
					display: flex;
					flex-direction: column;
					align-items: center;
					color: $u-content-color;
					font-size: 28rpx;
				}
			}

			.hint {
				padding: 20rpx 40rpx;
				font-size: 20rpx;
				color: $u-tips-color;

				.link {
					color: $u-warning;
				}
			}
		}
	}
</style>